/*
 * @Author: Joel
 * @Date: 2025-04-10 08:45:19
 * @LastEditors: Joel
 * @LastEditTime: 2025-04-17 10:36:01
 * @FilePath: /gd32f303cct6/usr/board_driver/rled.c
 * @Description: 
 * Copyright (C) 2025 YiJiaLink, All Rights Reserved. 
 * 2025-04-10 08:45:19
 */
#include"rled.h"

 static void rled_gpio_init(void);
 static void run_rled(enum PWM_DUTY PWM_DUTY);
 static void stop_rled(void);
 static struct rled_func rled;
 /**
  * @func: 
  * @description: 初始化rled
  * @param {rled_func} rled_func
  * @return {*}
  * @example: 
  */
 struct rled_func *rled_init(void)
 {
     struct rled_func *rled_func = &rled;
     rled_func->init_rled = rled_gpio_init;
     rled_func->run_rled = run_rled;
     rled_func->stop_rled = stop_rled;
     return rled_func;
 }
 /**
  * @func: 
  * @description: 初始化GPIO口
  * @return {*}
  * @example: 
  */
 static void rled_gpio_init(void)
 {
     /* enable the led clock */
     rcu_periph_clock_enable(RLED_GPIO_CLK);
     /* configure led GPIO port */ 
     gpio_init(RLED_GPIO_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ,RLED_PIN);
 
     GPIO_BC(RLED_GPIO_PORT) = RLED_PIN;
 
     return;
 }
 /**
  * @func: 
  * @description: 翻转电平启动buzzer
  * @return {*}
  * @example: 
  */
 static void run_rled(enum PWM_DUTY PWM_DUTY)
 {
     static uint8_t flag;

     if (flag == PWM_DUTY)
     {
    /* code */
    GPIO_BC(RLED_GPIO_PORT) = (uint32_t)RLED_PIN;
     }
     else if (flag == DUTY0)
     {

        GPIO_BOP(RLED_GPIO_PORT) = (uint32_t)RLED_PIN;
        flag = 0;
     }
    flag += DUTY25;
     return;
 }
 /**
  * @func: 
  * @description: 低电平关闭buzzer
  * @return {*}
  * @example: 
  */
 static void stop_rled(void)
 {
     gpio_bit_reset(RLED_GPIO_PORT, RLED_PIN);
     return;
 }
 
 